<template>
	<view>
		<view class="list-container">
			<!-- 检查信息 -->
			<view class="item">
				<view class="top-label" @click="retract(0)">
					<view>检查信息</view>
					<view v-if="showBasicInformation[0].show"><uv-icon name="arrow-down" size="40rpx" color="#000000"></uv-icon></view>
					<view v-else><uv-icon name="arrow-right" size="40rpx" color="#000000"></uv-icon></view>
				</view>
				<view class="info" v-if="showBasicInformation[0].show">
					<view class="row">
						<view class="title">检查地点:</view>
						<view class="con">{{dataForm.canteenName ? dataForm.canteenName : dataForm.schoolName}}</view>
					</view>
					<view class="row">
						<view class="title">指标名称:</view>
						<view class="con">{{dataForm.targetName}}</view>
					</view>
					<view class="row">
						<view class="title">检查日期:</view>
						<view class="con">{{dataForm.lawDate}}</view>
					</view>
					<view class="row">
						<view class="title">检查人:</view>
						<view class="con">{{dataForm.userName}}</view>
					</view>
				</view>
			</view>
			<!-- 检查内容 -->
			<view class="item">
				<view class="top-label" @click="retract(1)">
					<view>检查内容</view>
					<view v-if="showBasicInformation[1].show"><uv-icon name="arrow-down" size="40rpx" color="#000000"></uv-icon></view>
					<view v-else><uv-icon name="arrow-right" size="40rpx" color="#000000"></uv-icon></view>
				</view>
        <view class="info" v-if="showBasicInformation[1].show">
          <DaTree
              ref="DaTreeRef"
              :data="dataForm.lawBindEntryList"
              labelField="content"
              valueField="id"
              defaultExpandAll
              :show-annotation="true"
              :show-control="false"
              :show-annotation-look="true"
              :defaultCheckedKeys="defaultCheckedKeysValue"
          >
          </DaTree>
        </view>
			</view>
			<!-- 检查照片 -->
			<view class="item">
				<view class="top-label" @click="retract(2)">
					<view class="">检查照片</view>
					<view v-if="showBasicInformation[2].show"><uv-icon name="arrow-down" size="40rpx" color="#000000"></uv-icon></view>
					<view v-else><uv-icon name="arrow-right" size="40rpx" color="#000000"></uv-icon></view>
				</view>
				<view class="info" v-if="showBasicInformation[2].show">
					<view class="img-all">
            <fileUpload :tableId="dataForm.id" tableName="sup_law_item" type="photo" :watermarkFlag="true"
                        :maxCount="imageLength" :deletable="false" @initImage="initImage" width="72" height="72" />
					</view>
				</view>
			</view>
			<!-- 检查记录单 -->
			<view class="item">
				<view class="top-label">
					<view class="requireStar">检查记录单</view>
					<view class="zi-label">{{imageRecordLength}} / 3</view>
				</view>
				<view class="info" style="display: flex">
					<view style="display: flex">
            <fileUpload tableName="sup_law_item" type="bill" :watermarkFlag="true"
                        :maxCount="3" multiple :deletable="true" @imageListArray="imgRecordList" @delImageListArray="delRecordImgList"
                        @initImage="initRecordImage" width="72" height="72">
            </fileUpload>
					</view>
				</view>
			</view>
			<!-- 检查情况补充 -->
			<view class="item">
				<view class="top-label">
					<view>检查情况补充</view>
				</view>
				<view class="info">{{dataForm.lawItem.checkRecord||'--'}}</view>
			</view>
			<!-- 是否需要整改 -->
			<view class="item">
				<view class="top-label">
					<view>是否需要整改</view>
					<view style="color: #949494;font-size: 28rpx;">{{ dataForm.rectifyFlag=='0'?'否':'是' }}</view>
				</view>
				<view class="zheng-gai-zi" style="margin-left: 10rpx">整改意见：</view>
				<view class="content-item" style="margin-left: 10rpx">{{dataForm.lawItem.rectificationContent||'--'}}</view>
			</view>
			<!-- 检查人签名 -->
			<view class="item" style="margin-bottom: 200rpx">
				<view class="top-label">
					<view class="">检查人签名</view>
          <image :src="dataForm.superviseSign" mode="heightFix" style="height: 25px;"></image>
				</view>
			</view>
		</view>
		<view class="check-bottom-box" @click.stop>
			<button class="sure-button" @click.stop="submit()">确认</button>
		</view>
	</view>
</template>

<script setup>
import {ref, reactive, getCurrentInstance, defineProps} from "vue";
import supLawApi from "@/api/law/supLaw/supLaw";
const {proxy} = getCurrentInstance();
const entryType = ref(uni.getStorageSync('entryType'));
const props = defineProps({
  id:{
    type:String,
    default:"",
    required:true,
  }
});

const DaTreeRef = ref()

const defaultCheckedKeysValue = ref([])

const dataForm = ref({
  id:'',
  schoolName:'',
  targetName:'',
  lawDate:'',
  userName:'',
  rectifyFlag:'',
  superviseSign:null,
  lawItem:{
    checkRecord:'',
    rectificationContent:'',
  }
});

const checkList = ref([]);
let formData = reactive({
  id:"",
  rectifyFlag:0,
  entryType: '',
  lawType: '',
  lawItem: {
    fileList: [],
  }
});



const imageRecordLength = ref(0);

const showBasicInformation = reactive([{ show: true }, { show: true }, { show: true }]);
const value = ref('这里是一段文字主要描述食材平台采购情况的详细信息');
function retract(index) {
  showBasicInformation[index].show = !showBasicInformation[index].show;
}
const isActive = ref(-1);
function annotationShow(index) {
  if (isActive.value === index) {
    isActive.value = -1;
  } else {
    isActive.value = index;
  }
};
onMounted(()=>{
  getsupLawInfo(props.id);
  formData.id=props.id;
})
let getsupLawInfo = async (id) => {
  let res = await proxy.http.asyncGet(supLawApi.getInfo(id));
  if (res.code === 0 && res.data) {
      dataForm.value={...res.data};
      console.log('dataForm.value',dataForm.value)
      dataForm.value.lawItem={...dataForm.value.params[dataForm.value.lawStatus]};
      if(dataForm.value.lawItem){
        dataForm.value.photoFileList=dataForm.value.params[dataForm.value.lawStatus].fileList.filter(item=>item.type="photo");
        dataForm.value.billFileList=dataForm.value.params[dataForm.value.lawStatus].fileList.filter(item=>item.type="bill");
      }
	  formData.lawType = dataForm.value.lawType;
	  formData.entryType = dataForm.value.entryType;
    formData.targetId = dataForm.value.targetId;
    formData.targetName = dataForm.value.targetName;
	  formData.schoolId = dataForm.value.schoolId;
  } else {
    await uni.showToast({title: res.msg, icon: 'none'});
  }
}
/** 整改信息 */
const imageLength = ref(0); // 检查图片长度
let initImage = (imageList) => {
  imageLength.value = imageList.length;
};

/**初始化图片*/
let initRecordImage = (imageList) => {
  imageRecordLength.value = imageList.length;
};

/** 上传图片 **/
let imgRecordList = (addList, imageList)=>{
  formData.lawItem.fileList = addList;
  imageRecordLength.value = imageList.length;
}

/** 删除图片 **/
let delRecordImgList = (delFileIds, imageList) => {
  formData.delRecordFileIds = delFileIds;
  imageRecordLength.value = imageList.length;
};
let submit  = async () => {
	if (imageRecordLength.value> 0) {
		formData.rectifyFlag=dataForm.value.rectifyFlag
		let res = await proxy.http.asyncPost(supLawApi.editForBill,formData);
		if (res.code === 0) {
		  await uni.showToast({icon: 'success', title: '上传成功', duration: 2000});
		  setTimeout(() => {
			 goBack();
		  }, 1000)
		} else {
		  await uni.showToast({title: res.msg, icon: 'none'});
		  setTimeout(() => {
			goBack();
		  }, 1000)
		}
	} else {
		uni.showToast({
			icon: 'none',
			duration: 2000,
			title: '请上传检查记录单'
		});
	}
};

/** 返回上一页 */
let goBack = async () => {
  uni.$emit("refresh", {});
  await uni.navigateBack();
};
</script>
<style lang="scss" scoped>
@import '@/static/css/dailycheck/viewIndex.scss';
@import '@/static/css/dailycheck/common.scss';
::v-deep .placeholder-color {
	color: rgba(0, 0, 0, 0.3);
	font-size: 32rpx;
}
::v-deep .requireStar {
	width: 30%;
}
::v-deep .requireStar:after {
	vertical-align: bottom; //加上星号会上下居中，不加会在上角展示
	content: ' *';
	color: rgba(255, 59, 48, 1);
	font-size: 100%;
}
.zi-label {
  color: #9e9e9e;
  font-size: var(--uni-font-size-14);
}
.file-img {
	width: 140rpx;
	height: 140rpx;
	border-radius: 4px;
	margin-left: 10rpx;
}
.popup-title-1 {
	height: 112rpx;
	text-align: center;
	font-weight: bold;
	border-bottom: 1px solid #e7e7e7;
	line-height: 112rpx;
	background: #ffffff;
}
.up-popup-content {
	display: flex;
	flex-direction: column;
	justify-content: center;
	height: 360rpx;
	background: #f5f5f5;
	.select-one {
		height: 110rpx;
		background: #ffffff;
		margin-top: -140rpx;
		text-align: center;
		border-bottom: 1px solid #e7e7e7;
		line-height: 110rpx;
	}
	.select-two {
		height: 110rpx;
		line-height: 110rpx;
		background: #ffffff;
		text-align: center;
		border-bottom: 1px solid #e7e7e7;
	}
	.bottom-box {
		height: 110rpx;
		line-height: 110rpx;
		background: #ffffff;
		text-align: center;
	}
}
.delet-img {
	height: 32rpx;
	width: 32rpx;
	position: absolute;
	right: 0;
	top: 0;
}
</style>
